package com.h3c.tj_nsh.Widget;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.h3c.tj_nsh.R;


/**
 * Time: 2016/4/23.
 * Author:Chen  .
 * TabHost的TabIndicatorView
 */
public class TabIndicatorView extends LinearLayout {
    private ImageView ivTabIcon;
    private TextView tvTabHint;
    private int normalIconId;
    private int focusIconId;
    private LinearLayout mLlTabIndicator;

    public TabIndicatorView(Context context) {
        super(context, null);
        // 将布局文件和 代码进行绑定
        View.inflate(context, R.layout.tab_indicator, this);
        ivTabIcon = (ImageView) findViewById(R.id.tab_indicator_icon);
        tvTabHint = (TextView) findViewById(R.id.tab_indicator_hint);
        mLlTabIndicator = (LinearLayout) findViewById(R.id.tab_indicator);
    }

    public TabIndicatorView(Context context, AttributeSet attrs) {
        super(context, attrs);


    }


    // 设置tab的title
    public void setTabTitle(String title) {
        tvTabHint.setText(title);
    }

    public void setTabTitle(int titleId) {
        tvTabHint.setText(titleId);
    }

    // 初始化图标
    public void setTabIcon(int normalIconId, int focusIconId) {
        this.normalIconId = normalIconId;
        this.focusIconId = focusIconId;

        ivTabIcon.setImageResource(normalIconId);
    }
    public void setTabIcon(int normalIconId) {
        this.normalIconId = normalIconId;
        this.focusIconId = focusIconId;

        ivTabIcon.setImageResource(normalIconId);
    }

    // 设置选中
    public void setTabSelected(boolean selected) {
        if (selected) {
            mLlTabIndicator.setBackgroundColor(Color.rgb(0,150,136));
            tvTabHint.setTextColor(Color.RED);
        } else {
            mLlTabIndicator.setBackgroundColor(Color.WHITE);
            tvTabHint.setTextColor(Color.BLACK);
        }
    }
}
